<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备类别" prop="equipCateg">
        <el-select v-model="queryParams.taskStatus" placeholder="请选择设备类别" clearable>
          <el-option v-for="dict in dict.type.iti_equip_categ" :key="dict.value" :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="营销工号" prop="staffNo">
        <el-input v-model="queryParams.staffNo" placeholder="请输入营销工号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="盘点日期" prop="chkDate">
        <el-date-picker clearable v-model="queryParams.chkDate" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择盘点日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="归档日期" prop="arcerDate">
        <el-date-picker clearable v-model="queryParams.arcerDate" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择归档日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="任务状态" prop="taskStatus">
        <el-select v-model="queryParams.taskStatus" placeholder="请选择任务状态" clearable>
          <el-option v-for="dict in dict.type.status_code" :key="dict.value" :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="mdInvChkTaskList" @selection-change="handleSelectionChange">
      <el-table-column label="任务标识" align="center" prop="taskId" />
      <el-table-column label="库房标识" align="center" prop="whId" />
      <el-table-column label="库房名称" align="center" prop="whName" min-width="110px" />
      <el-table-column label="库区标识" align="center" prop="whAreaId" />
      <el-table-column label="库区名称" align="center" prop="whAreaname" />
      <el-table-column label="存放区标识" align="center" prop="storeAreaId" min-width="110px" />
      <el-table-column label="存放区标识" align="center" prop="storeAreaName" min-width="110px" />
      <el-table-column label="周转柜资产编号" align="center" prop="cabinetBarCode" min-width="150px" />
      <el-table-column label="供电单位" align="center" prop="orgNo" />
      <el-table-column label="设备类别" align="center" prop="equipCateg">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.iti_equip_categ" :value="scope.row.equipCateg" />
        </template>
      </el-table-column>
      <el-table-column label="接线方式" align="center" prop="wiringMode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.iti_wiring_mode" :value="scope.row.wiringMode" />
        </template>
      </el-table-column>
      <el-table-column label="设备规格" align="center" prop="specCode" />
      <el-table-column label="盘点人" align="center" prop="inventoryChecker" />
      <el-table-column label="营销工号" align="center" prop="staffNo" />
      <el-table-column label="盘点日期" align="center" prop="chkDate" min-width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.chkDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="归档人员" align="center" prop="arcPersonNo" />
      <el-table-column label="归档日期" align="center" prop="arcerDate" min-width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.arcerDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="盘点任务数量" align="center" prop="inventoryQty" min-width="130px" />
      <el-table-column label="任务状态" align="center" prop="taskStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.status_code" :value="scope.row.taskStatus" />
        </template>
      </el-table-column>
      <el-table-column label="任务执行失败原因" align="center" prop="failReason" min-width="180px" />
      <el-table-column label="操作标识" align="center" prop="operId" />
      <el-table-column label="任务状态" align="center" prop="statusCode" />
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" min-width="200px">
        <template slot-scope="scope">
          <el-button size="small" type="primary" @click="taskDetails(scope.row)">任务明细</el-button>
          <el-button size="small" type="success" @click="taskResults(scope.row)">任务结果</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <el-dialog :title="title" :visible.sync="open" width="1200px" v-if="this.title == '任务明细'">
      <el-table v-loading="loading" :data="gridData" border>
        <el-table-column label="明细标识" align="center" prop="dtlId" />
        <el-table-column label="任务标识" align="center" prop="taskId" />
        <el-table-column label="设备类别" align="center" prop="equipCateg">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.iti_equip_categ" :value="scope.row.equipCateg" />
          </template>
        </el-table-column>
        <el-table-column label="设备标识" align="center" prop="equipId" />
        <el-table-column label="资产条形码" align="center" prop="barCode" min-width="100px" />
        <el-table-column label="库房标识" align="center" prop="whId" v-if="false" />
        <el-table-column label="库房名称" align="center" prop="whName" min-width="100px" />
        <el-table-column label="库区标识" align="center" prop="whAreaId" v-if="false" />
        <el-table-column label="库区名称" align="center" prop="whAreaname" />
        <el-table-column label="存放区标识" align="center" prop="storeAreaId" v-if="false" />
        <el-table-column label="存放区名称" align="center" prop="storeAreaName" min-width="100px" />
        <el-table-column label="周转柜资产编号" align="center" prop="cabinetBarCode" min-width="100px" />
        <el-table-column label="柜单元标识" align="center" prop="unitId" v-if="false" />
        <el-table-column label="储位标识" align="center" prop="storeLocId" v-if="false" />
        <el-table-column label="储位名称" align="center" prop="storeLocName" />
        <el-table-column label="操作标识" align="center" prop="operId" v-if="false" />
        <el-table-column label="是否完成" align="center" prop="isComplete">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.iti_is_complete" :value="scope.row.isComplete" />
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="num > 0" :total="num" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="taskDetails" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">返 回</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="open" width="1200px" v-if="this.title == '任务结果'">
      <el-table v-loading="loading" :data="taskResultsList" border>
        <el-table-column label="盘点结果明细标识" align="center" prop="invchkRsltId" min-width="130px" />
        <el-table-column label="任务标识" align="center" prop="taskId" />
        <el-table-column label="设备类别" align="center" prop="equipCateg" min-width="100px">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.iti_equip_categ" :value="scope.row.equipCateg" />
          </template>
        </el-table-column>
        <el-table-column label="设备标识" align="center" prop="equipId" />
        <el-table-column label="资产条形码" align="center" prop="barCode" min-width="120px" />
        <el-table-column label="库房标识" align="center" prop="whId" v-if="false" />
        <el-table-column label="库房名称" align="center" prop="whName" min-width="120px" />
        <el-table-column label="库区标识" align="center" prop="whAreaId" v-if="false" />
        <el-table-column label="库区名称" align="center" prop="whAreaname" />
        <el-table-column label="存放区标识" align="center" prop="storeAreaId" v-if="false" min-width="120px" />
        <el-table-column label="存放区名称" align="center" prop="storeAreaName" min-width="120px" />
        <el-table-column label="周转柜资产编号" align="center" prop="cabinetBarCode" min-width="120px" />
        <el-table-column label="柜单元标识" align="center" prop="unitId" v-if="false" min-width="120px" />
        <el-table-column label="储位标识" align="center" prop="storeLocId" v-if="false" />
        <el-table-column label="储位名称" align="center" prop="storeLocName" />
        <el-table-column label="盘点人" align="center" prop="inventoryChecker" />
        <el-table-column label="盘点日期" align="center" prop="inventoryChkDate" min-width="220px" />
        <el-table-column label="盘点结果" align="center" prop="rsltCode">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.iti_rslt_code" :value="scope.row.rsltCode" />
          </template>
        </el-table-column>
        <el-table-column label="档案是否存在" align="center" prop="docExistFlag" min-width="100px">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.iti_doc_exist_flag" :value="scope.row.docExistFlag" />
          </template>
        </el-table-column>
        <el-table-column label="预警处理标识" align="center" prop="handleFlag" min-width="100px">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.iti_handle_flag" :value="scope.row.handleFlag" />
          </template>
        </el-table-column>
        <el-table-column label="处理人" align="center" prop="handlerNo" />
        <el-table-column label="处理方式" align="center" prop="handleMode" min-width="120px">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.iti_handle_mode" :value="scope.row.handleMode" />
          </template>
        </el-table-column>
        <el-table-column label="处理日期" align="center" prop="handleDate" min-width="220px" />
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="操作标识" align="center" prop="operId" v-if="false" />
      </el-table>
      <pagination v-show="nums > 0" :total="nums" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="taskResults" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">返 回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMdInvChkTask, getMdInvChkTaskDetails, getMdInvChkTaskResults } from "@/api/storage/mdInvChkTask";

export default {
  name: "MdInvChkTask",
  dicts: ["iti_equip_categ", "iti_wiring_mode", "status_code", "iti_rslt_code", "iti_doc_exist_flag", "iti_handle_flag", "iti_handle_mode", "iti_is_complete"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      num: 0,
      nums: 0,
      // 盘点任务信息表格数据
      mdInvChkTaskList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        whId: null,
        whAreaId: null,
        storeAreaId: null,
        cabinetBarCode: null,
        orgNo: null,
        equipCateg: null,
        wiringMode: null,
        specCode: null,
        inventoryChecker: null,
        staffNo: null,
        chkDate: null,
        arcPersonNo: null,
        arcerDate: null,
        inventoryQty: null,
        taskStatus: null,
        failReason: null,
        operId: null,
        statusCode: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      //任务明细数据
      gridData: [],
      //任务结果数据
      taskResultsList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询盘点任务信息列表 */
    getList() {
      this.loading = true;
      listMdInvChkTask(this.queryParams).then(response => {
        this.mdInvChkTaskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //返回按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.taskId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 任务明细 */
    taskDetails(row) {
      this.open = true
      let params = {}
      const taskId = row.taskId || this.ids
      params.taskId = taskId
      getMdInvChkTaskDetails(params).then(response => {
        this.gridData = response.rows
        this.num = response.total
        this.title = "任务明细"
      })
    },
    /** 任务结果 */
    taskResults(row) {
      this.open = true
      let params = {}
      const taskId = row.taskId || this.ids
      params.taskId = taskId
      getMdInvChkTaskResults(params).then(response => {
        this.taskResultsList = response.rows
        this.nums = response.total
        this.title = "任务结果"
      })
    },
  }
};
</script>
<style scoped>
div /deep/.el-dialog {
  margin-top: 15vh !important;
}

.el-form-item {
  margin-right: 28px;
}
</style>